/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entidades.Concesionaria;
import entidades.Contrato;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author RENZO
 */
public class ContratoDAO extends AbstractDAO {
    
    public static List<Contrato>getContratosByNombreConcesionaria(String nombre){
        List<Contrato>listaContratos = new ArrayList<Contrato>();
        Contrato objContrato = new Contrato();
        try {
            PreparedStatement ps = prepararConexionPrepared(" SELECT ct.contrato_id AS contratoid, ct.contrato_fechaini as fechainicio, ct.contrato_fechafin as fechafin, c.concesionaria_id as concesionariaid, c.concesionaria_razonsocial as razon  "
                    + "FROM CONTRATO CT JOIN CONCESIONARIA C ON C.CONCESIONARIA_ID = CT.CONCESIONARIA_ID "
                    + "WHERE C.CONCESIONARIA_RAZONSOCIAL ILIKE '%"+nombre+"%'");
            ResultSet rs = realizarConexionGET(ps);
            while(rs.next()){
                objContrato = new Contrato();
                objContrato.setId(rs.getLong("contratoid"));
                objContrato.setFechaInicio(new Date(rs.getTime("fechainicio").getTime()));
                objContrato.setFechaFin(new Date(rs.getTime("fechafin").getTime()));
                Concesionaria objCons = new Concesionaria();
                objCons.setId(rs.getLong("concesionariaid"));
                objCons.setRazonSocial(rs.getString("razon"));
                objContrato.setConcesionaria(objCons);
                listaContratos.add(objContrato);
            }
        } catch (SQLException ex) {
            Logger.getLogger(MedidorDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return listaContratos;
    }
}
